package com.substation.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.greenentity.Unit;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;
import com.substation.R;
import com.substation.ui.activity.PatroDetailActivity;
import com.substation.utils.SPUtils;

/**
 * Created by admin on 2018/5/16.
 */

public class PatroAdapter extends SuperAdapter<Unit> {

    Context context;

    public PatroAdapter(int layoutId) {
        super(layoutId);
    }

    public PatroAdapter(Context context) {
        this(R.layout.content_patro_content);
        this.context = context;
    }

    @Override
    public void bindView(ViewHolder viewHolder, final Unit s, int i) {
        ((TextView) viewHolder.getView(R.id.name)).setText(s.getTourUnit());
        View layout = viewHolder.getView(R.id.layout);
        if (s.getComplete() == 0) {
            layout.setBackgroundResource(R.drawable.shape_stroke_red_radius);
        } else {
            if (s.getExcount() > 0) {//有异常
                layout.setBackgroundResource(R.drawable.shape_stroke_green_radius_ex);
            } else {
                layout.setBackgroundResource(R.drawable.shape_stroke_green_radius);
            }
        }
        layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SPUtils.put(context, "unit", JSON.toJSONString(s));
                context.startActivity(new Intent(context, PatroDetailActivity.class));
            }
        });
    }
}
